package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import control.ActListener;
import control.MouseListener;

import model.ModelClass;
import model.Variables;

public class CenterHomePage extends JPanel {
	MainF mainF;
	ModelClass modelClass;
	ActListener ac;
	MouseListener mL;
	WeatherPanel weatherPanel;
	Variables variables;

	Image bgImage = null;
	
	private JButton btnGarden;
	private JButton btnCalender;
	private JButton btnIE;
	private JButton btnMail;
	private JButton btnEmployees;
	private JButton btnFinance;
	private JButton btnMaps;

	public CenterHomePage(MainF mainF) {
		setBackground(Color.BLACK);
		setPreferredSize(new Dimension(1280, 690));
		setLayout(null);
		this.mainF = mainF;
		this.modelClass = mainF.getModel();
		this.ac = mainF.getAc();
		this.mL = mainF.getmL();
		this.variables = mainF.getModel().getVariables();

		setName("CenterHomePage");
		
		btnGarden = new JButton();
		btnGarden.setOpaque(false);
		btnGarden.setBackground(null);
		btnGarden.setBorder(null);
		btnGarden.setActionCommand("Home");
		btnGarden.addActionListener(ac);
		btnGarden.setIcon(variables.getBtnGardenTileIcon());
		btnGarden.setPressedIcon(variables.getBtnGardenTilePressedIcon());
		btnGarden.setBounds(12,50,250,120);
		add(btnGarden);
		
		btnCalender = new JButton();
		btnCalender.setOpaque(false);
		btnCalender.setBackground(null);
		btnCalender.setBorder(null);
		btnCalender.setIcon(variables.getBtnCalenderTileIcon());
		btnCalender.setPressedIcon(variables.getBtnCalenderTilePressedIcon());
		btnCalender.setBounds(12,175,250,120);
		add(btnCalender);
		
		btnIE = new JButton();
		btnIE.setOpaque(false);
		btnIE.setBackground(null);
		btnIE.setBorder(null);
		btnIE.setIcon(variables.getBtnIETileIcon());
		btnIE.setPressedIcon(variables.getBtnIETilePressedIcon());
		btnIE.setBounds(12,300,120,120);
		add(btnIE);
		
		btnMail = new JButton();
		btnMail.setOpaque(false);
		btnMail.setBackground(null);
		btnMail.setBorder(null);
		btnMail.setIcon(variables.getBtnMailTileIcon());
		btnMail.setPressedIcon(variables.getBtnMailTilePressedIcon());
		btnMail.setBounds(142,300,120,120);
		add(btnMail);
		
		btnEmployees = new JButton();
		btnEmployees.setOpaque(false);
		btnEmployees.setBackground(null);
		btnEmployees.setBorder(null);
		btnEmployees.setIcon(variables.getBtnEmployeesTileIcon());
		btnEmployees.setPressedIcon(variables.getBtnEmployeesTilePressedIcon());
		btnEmployees.setBounds(12,425,250,120);
		add(btnEmployees);
		
		btnFinance = new JButton();
		btnFinance.setOpaque(false);
		btnFinance.setBackground(null);
		btnFinance.setBorder(null);
		btnFinance.setIcon(variables.getBtnFinanceTileIcon());
		btnFinance.setPressedIcon(variables.getBtnFinanceTilePressedIcon());
		btnFinance.setBounds(12,550,120,120);
		add(btnFinance);
		
		btnMaps = new JButton();
		btnMaps.setOpaque(false);
		btnMaps.setBackground(null);
		btnMaps.setBorder(null);
		btnMaps.setIcon(variables.getBtnMapsTileIcon());
		btnMaps.setPressedIcon(variables.getBtnMapsTilePressedIcon());
		btnMaps.setBounds(142,550,120,120);
		add(btnMaps);
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		try {
			ImageIcon ii = (ImageIcon) variables.getBgCenterHomePage();
			bgImage = ii.getImage();
		} catch (Exception ex) {
			// Error message if file dosn't exist
			String message = "File load failed: " + ex.getMessage();
			g.drawString(message, 40, 40);
		}
		// Draws picture
		g2.drawImage(bgImage, 0, 0, 1360, 690, null);
	}
}
